<?php
namespace app\common\model;
use think\Model;
class Config extends Model{	
	// 开启自动写入时间戳字段
	protected $autoWriteTimestamp = true;	
    // 定义时间戳字段名
    protected $createTime = '';
    protected $updateTime = '';	
	// 自动完成
	protected $auto = ['name', 'uptime'];
	protected $insert = ['addtime'];
	protected $update = [];
    protected function setUpTimeAttr(){
        return time();
    }
    protected function setAddTimeAttr(){
        return time();
    }	
    protected function setNameAttr($value){
        return strtolower($value);
    }
    protected function getTypeTextAttr($value, $data){
    	$type = config('setting.class_list');
    	$type_text = explode(',', $type[$data['type']]);
        return $type_text[0];
    }
	public function datas(){
		$config = include  RUNTIME_PATH.'conf/config.php';
		$list = db('Config')->field('id,name,title,extra,remark,type,class,value,other,style,status')->where('status',1)->order('sort')->select();
		foreach($list as $key=>$val){
			//$config[$group_type[$val['group']]][$val['name']]=$this->parse($val['type'],$val['value']);
			$data[$val['class']][$key]=$val;
			$data[$val['class']][$key]['value']=arr($val['type'],$config[$val['class']][$val['name']]);
		}
		return $data;
	}
	public function up($config=''){
		if(!$config){
		     $config = include  RUNTIME_PATH.'conf/config.php';
		}
		$list = db('Config')->field('id,name,title,extra,remark,type,class,value,style,other,status')->where('status',1)->order('sort')->select();
		foreach($list as $key=>$val){			
			$data[$val['class']][$val['name']]=parse($val['type'],$config[$val['class']][$val['name']]);
			//$data[$val['class']][$key]=$val;
			//$data[$val['class']][$key]['value']=$this->arr($val['type'],$config[$val['class']][$val['name']]);
		}
		return $data;
	}	
}
// +----------------------------------------------------------------------
// | ZanPianCMS
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.zanpiancms.com All rights reserved.
// +----------------------------------------------------------------------
// | BBS:  <http://www.zanpiancms.cc>
// +----------------------------------------------------------------------
?>